package org.metasketch.editor.toolbox;

import java.util.HashMap;
import java.util.Map;

public class InstanceCreatorRegistry {

	Map<String, Class> instanceCreatorPerType = new HashMap<String, Class>();

	public void register(String type, Class graphic) {

		if (IInstanceCreator.class.isAssignableFrom(graphic))
			instanceCreatorPerType.put(type, graphic);
	}

	public IInstanceCreator get(String name) throws Throwable {
		Class type = instanceCreatorPerType.get(name);

		if (type == null)
			return null;

		IInstanceCreator node = (IInstanceCreator) type.newInstance();
		return node;
	}

}
